//
//  IdeaFeedbackViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/9.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "IdeaFeedbackViewController.h"

@interface IdeaFeedbackViewController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTF;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UIView *titleView;
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIView *phoneView;
@property (weak, nonatomic) IBOutlet UILabel *placeLabel;
@property (weak, nonatomic) IBOutlet UITextView *contentTV;
@property (weak, nonatomic) IBOutlet UIButton *sureButton;

@end

@implementation IdeaFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowleft-icon"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction:)];
    self.navigationItem.leftBarButtonItem = back;
    [_titleTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    [_phoneTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    
    self.titleView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.titleView.layer.borderWidth = 1.0f;
    
    self.contentView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.contentView.layer.borderWidth = 1.0f;
    
    self.phoneView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.phoneView.layer.borderWidth = 1.0f;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textLengthChange) name:UITextViewTextDidChangeNotification object:self.contentTV];
    
    [self.sureButton setBackgroundImage:[UIImage imageWithColor:RGBColor(86, 54, 157)] forState:(UIControlStateHighlighted)];
    
}


- (void)backAction:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
//监听纯文字中文字长度
-(void)textLengthChange{
    NSString *str =  [self.contentTV.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if(str.length > 0){
        self.placeLabel.text = @"";
    }else{
        
        self.placeLabel.text = @"请写下您对平台的感受，我们将认真听取您的意见，努力提供优质的服务。";
    }
    
}

- (IBAction)submitAction {
    NSString*str = [self.titleTF.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSString*str1 = [self.contentTV.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    if (str.length==0) {
        [MBProgressHUD showError:@"请输入您的反馈主题"];
        return;
    }
    if (str1.length==0) {
        [MBProgressHUD showError:@"请写下您对平台的感受，我们将认真听取您的意见 ，努力提供优质的服务。"];
        return;
    }
    
    NSDictionary *param = @{@"title" : self.titleTF.text,
                            @"content" : self.contentTV.text,
                            @"contact" : self.phoneTF.text,
                            };
    [LSRequestManager postRequestWithURL:HUOBI(@"api/user/feedback")
                                  params:param
                                 success:^(NSDictionary *responseData) {
                                     if ([responseData[@"ret"] integerValue ] == 0) {
                                         [MBProgressHUD showError:responseData[@"msg"]];
                                         
                                         [self.navigationController popViewControllerAnimated:YES];
                                         
                                         
                                     } else {
                                         [MBProgressHUD showError:responseData[@"msg"]];
                                     }
                                 }
                                 failure:^(NSError *error) {
                                     
                                 }
                                 showHUD:NO];
    
    
    
    
    
    
    
    
    
    
}


@end
